package midone.exchangeskill.utils;

import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import javax.inject.Inject;

/**
 * Created by NekoNeko on 2016/12/5.
 * 页面加载动画、数据填充、异常情况 等状态显示
 */

public class PageStateManager {
    static String TAG = "PageStateManager";
    View contentView;//内容布局
    View progressView;//进度条布局
    View contentError;//出现错误布局
    View contentEmpty;//没有内容布局

    @Inject
    public PageStateManager() {
    }

    public PageStateManager initPage(View view) {
        PageStateManager pageStateManager = new PageStateManager();
        this.contentView = view;
        return pageStateManager;
    }

    /**
     * 显示加载动画
     *
     * @param layoutResId
     */
    public void showLoadingProgress(@LayoutRes int layoutResId) {
        ViewGroup viewGroup = (ViewGroup) contentView.getParent();
        viewGroup.removeView(contentView);
        progressView = LayoutInflater.from(contentView.getContext()).inflate(layoutResId, viewGroup, false);
        viewGroup.addView(progressView);
    }

    /**
     * 删除加载布局，添加内容布局
     */
    public void showContentView() {
        ViewGroup viewGroup = (ViewGroup) progressView.getParent();
        viewGroup.addView(contentView);
        viewGroup.removeView(progressView);
    }
}
